package io.polly.repository;

import io.polly.entity.ExamQuestionAnswer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ldz
 * @version V1.0
 * @title: ExamQuestionAnswerDAO
 * @description: TODO(用一句话描述该文件做什么)
 * @date: 2022/4/6 16:06
 */
@Service
public class ExamQuestionAnswerDAO {

    @Autowired
    @Qualifier(value = "namedParameterJdbcTemplate")
    private NamedParameterJdbcTemplate tidbJdbcTemplate;

    public static String getExamQuestionAnswerByExamIdAndUserIdAndQuestionIdSql = "SELECT * FROM t_exam_question_answer where exam_id=:examId and user_id=:userId and question_id=:questionId";
    public List<ExamQuestionAnswer> getExamQuestionAnswerByExamIdAndUserIdAndQuestionId(String examId, Long userId, String questionId){
        Map<String, Object> param = new HashMap<>();
        param.put("examId", examId);
        param.put("userId", userId);
        param.put("questionId", questionId);
        return  tidbJdbcTemplate.query(getExamQuestionAnswerByExamIdAndUserIdAndQuestionIdSql, param, BeanPropertyRowMapper.newInstance(ExamQuestionAnswer.class));

    }
}
